package wallet

import (
	"errors"
	"fmt"
)

// Bitcoin 比特币
type Bitcoin int

// Wallet is wallet
type Wallet struct {
	balance Bitcoin
}

func (w *Wallet) deposit(amount Bitcoin) {
	w.balance += amount
}

// ErrInsufficientFunds 金额负数时，报错
var ErrInsufficientFunds = errors.New("cannot withdraw, insufficient funds")

func (w *Wallet) withdraw(amount Bitcoin) error {
	if amount > w.balance {
		return ErrInsufficientFunds
	}
	w.balance -= amount
	return nil
}

func (w *Wallet) getBalance() Bitcoin {
	return w.balance
}

func (b Bitcoin) String() string {
	return fmt.Sprintf("%d BTC", b)
}
